<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: liunwcj
 * Date: 15-5-29
 * Time: 下午5:44
 */
class User_model extends CI_Model
{
    const TB_USER = 'user';
    function __construct() {
        parent::__construct();
        $this->load->database();
    }

    function get_all_user(){
        $query = $this->db->get(self::TB_USER);
        return $query->result();
    }

    // 通过用户名获取用户记录
    function get_username($username){
        $this->db->where('username',$username);
        $query = $this->db->get('user');
        // 返回数据条数
        if($query->num_rows() == 1){
            return $query->row();
        }else{
            return false;
        };
    }

    // 用户名不存在时，返回false
    // 用户名存在时，验证密码是否正确
    function pwd_check($username,$password){
        if($user = $this->get_username($username)){
           return $user->password == $password ? true : false;
        }
        return false;
    }

    function set_user($arrs){
        $query = $this->db->insert(self::TB_USER,$arrs);
        return $this->db->affected_rows();
    }

}
